package com.example.mybatisplus.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.mybatisplus.mapper.ConsultMergeMapper;
import com.example.mybatisplus.mapper.EndReportMapper;
import com.example.mybatisplus.mapper.UserMapper;
import com.example.mybatisplus.model.domain.ConsultMerge;
import com.example.mybatisplus.model.domain.EndReport;
import com.example.mybatisplus.model.domain.User;
import com.example.mybatisplus.service.EndReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lxp
 * @since 2022-05-31
 */
@Service
public class EndReportServiceImpl extends ServiceImpl<EndReportMapper, EndReport> implements EndReportService {

    @Autowired
    private UserMapper userMapper;
    @Autowired
    private ConsultMergeMapper consultMergeMapper;

    @Autowired
    private EndReportMapper endReportMapper;

    @Override
    public void addEndReport(Long stuId) {
        User user = userMapper.selectById(stuId);
        ConsultMerge consultMerge = consultMergeMapper.getMergeById(stuId);
        EndReport endReport = new EndReport();
        endReport.setStuId(stuId);
        endReport.setConId(consultMerge.getId());
        endReport.setStuName(user.getStuName());
        endReport.setSex(user.getSex());
        endReport.setPhone(user.getPhone());
        endReport.setConsultCount(consultMerge.getConsultCount());


        endReportMapper.addEndReport(endReport);
    }

    @Override
    public boolean isExist(Long stuId) {
        String stuid = endReportMapper.isExist(stuId);
        return stuid != null;
    }

    @Override
    public List<EndReport> getAllEndReport() {
        return endReportMapper.getAllEndReport();
    }
}
